
<div class="container-fluid">

	<!-- affichage des messages Flash-->
	<div class="row-fluid">
		<div class="span12">
			<?php echo $this->Session_gpp->flash(); ?>
	 	</div>
	</div>

	<!-- Chemin fil conducteur -->
  	<div class="row-fluid">
		<div class="span12">
			<ul class="breadcrumb">
		      	<?php 
					echo '<li>'.$this->Html->link('Applications',array('controller'=>'applications','action'=>'index')).'</span>/</span></li>';
				?>
				<?php 
					echo '<li>'.$this->Html->link(h($sonapp['Application']['name']),array('controller'=>'applications','action'=>'View',$sonapp['Application']['id'])).'</span>/</span></li>';
				?>
				<?php 
					echo '<li>'.$this->Html->link(h($versionencours['Version']['name']),array('controller'=>'versions','action'=>'View',$versionencours['Version']['id'])).'</span>/</span></li>';
				?>
				<?php 
					echo '<li">'.$this->Html->link(h($satable['Table']['name']),array('controller'=>'tables','action'=>'View',$satable['Table']['id'], $versionencours['Version']['id']))."</span>/</span></li>";
				?>
				<?php 
					echo '<li class="active">'.$this->Html->link(h($rupture['Rupture']['name']),array('controller'=>'tables','action'=>'View',$rupture['Rupture']['id'], $versionencours['Version']['id']))."</li>";
				?>
			</ul>
		</div>
	</div>

	<!-- entete des onglets -->
	<div class="row-fluid">
		<div class="span12">
			<ul id="tab" class="nav nav-tabs">
			  	<li><a href="#Ruptures" data-toggle="tab">Ruptures</a></li>
			  	<li><a href="#Colonnes" data-toggle="tab">Colonnes</a></li>
			  	<li class="active"><a href="#Lignes" data-toggle="tab">Lignes</a></li>
			</ul>
	 	</div>
	</div>

	<!-- detail des onglets -->
	<div class="row-fluid">
		<div class="span12">
	<div id="myTabContent" class="tab-content">
	  	<!-- Onglet Ruptures -->
		<div class="tab-pane" id="Ruptures">
	  		<div class="navbar"/>
				<div class="navbar-inner_gpp">
					<div class="container-fluid">
						<div class="nav-collapse">
							<div class="row-fluid">
								<div class="span2">
									<a href="<?php echo $this->request->webroot;?>ruptures/add/<?php echo $satable['Table']['id'];?>/<?php echo $versionencours['Version']['id'];?>" class="btn btn-primary btn-small" >
										<i class="icon-plus-sign icon-white"></i><?php echo __(' Rupture')?>
									</a>
								</div>
								<div class="span2">
									<p>
										<a href="#" class="btn btn-danger btn-small" onclick="if (confirm('Are you sure you want to delete?')) 
											{ 
												document.post_rupture_delete.submit(); 
											} 
										event.returnValue = false; 
										return false;"><i class="icon-trash icon-white"></i><?php echo __(' Delete') ?></a>
									</p>
								</div>
								<div class="span8">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="page-header">
				<?php if (!empty($satable['Rupture'])):?>
					<form action="<?php echo $this->request->webroot;?>ruptures/delete" name="post_rupture_delete" id="post_rupture_delete" method="post">
						<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
							<thead>
								<tr>
									<th width="1px"><?php echo __('Id'); ?></th>
									<th><?php echo __('Name'); ?></th>
									<th><?php echo __('Description'); ?></th>
									<th width="1px"></th>
								</tr>
							</thead>
							<tbody>	
								<?php
									$i = 0;
									foreach ($satable['Rupture'] as $rupture): ?>
										<tr>
											<td><?php echo $rupture['id'];?></td>
											<td><?php echo h($rupture['name']);?></td>
											<td><?php echo h($rupture['description']);?></td>
											<td class="actions">
												<!--p>
													<?php echo $this->Moninput->deleteInverse(
																__('Delete Rupture'),
																$rupture['id'], 
																'Applications',
																__('Are you sure you want to delete # '.$rupture['id'].'?')
															); ?>
												</p-->
												<input type="checkbox" name="rupture[]" value="<?php echo $rupture['id'];?>"/> 
											</td>
										</tr>
									<?php endforeach; 
								?>
							</tbody>	
						</table>
					</form>
				<?php endif; ?>
			</div>
		</div>

	  	<!-- Onglet Colonnes -->
		<div class="tab-pane" id="Colonnes">
	  		<div class="navbar"/>
				<div class="navbar-inner_gpp">
					<div class="container-fluid">
						<div class="nav-collapse">
							<div class="row-fluid">
								<div class="span2">
									<a href="<?php echo $this->request->webroot;?>colonnes/add/<?php echo $satable['Table']['id'];?>/<?php echo $versionencours['Version']['id'];?>" class="btn btn-primary btn-small" >
										<i class="icon-plus-sign icon-white"></i><?php echo __(' Colonne')?>
									</a>
								</div>
								<div class="span2">
									<p>
										<a href="#" class="btn btn-danger btn-small" onclick="if (confirm('Are you sure you want to delete?')) 
											{ 
												document.post_colonne_delete.submit(); 
											} 
										event.returnValue = false; 
										return false;"><i class="icon-trash icon-white"></i><?php echo __(' Delete') ?></a>
									</p>
								</div>
								<div class="span8">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="page-header">
				<?php if (!empty($satable['Colonne'])):?>
					<form action="<?php echo $this->request->webroot;?>colonnes/delete" name="post_colonne_delete" id="post_colonne_delete" method="post">
						<input type="hidden" name="_method" value="POST"/>
						<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
							<thead>
								<tr>
									<th width="1px"><?php echo __('Id'); ?></th>
									<th><?php echo __('Name'); ?></th>
									<th><?php echo __('Type'); ?></th>
									<th><?php echo __('TopPk'); ?></th>
									<th><?php echo __('Description'); ?></th>
									<th width="1px"></th>
								</tr>
							</thead>
							<tbody>	
								<?php
									$i = 0;
									foreach ($satable['Colonne'] as $colonne): ?>
										<tr>
											<td><?php echo $colonne['id'];?></td>
											<td align="left"><?php echo $this->Html->link(h($colonne['name']),array('controller'=>'colonnes','action'=>'view',$colonne['id'])); ?>&nbsp;
											</td>
											<td><?php echo h($colonne['pgtypecol_name']); ?>&nbsp; <?php if ($colonne['longueur']) {	echo "(".h($colonne['longueur']).")"; } ?></td>
											<td><?php echo $colonne['topPk'];?></td>
											<td><?php echo nl2br($colonne['description']);?></td>
											<td class="center">
												<p>
													<?php /*echo $this->Moninput->delete(
																__('Delete'),
																$colonne['id'], 
																'Colonnes',
																__('Are you sure you want to delete # '.$colonne['id'].'?')
															); */
													?>
													<input type="checkbox" name="colonne[]" value="<?php echo $colonne['id'];?>"/> 
												</p>
											</td>
										</tr>
									<?php endforeach; 
								?>
							</tbody>
						</table>
					</form>
				<?php endif; ?>
			</div>
		</div>

	  	<!-- Onglet Lignes -->
		<div class="tab-pane active" id="Lignes">
	  		<div class="navbar"/>
				<div class="navbar-inner_gpp">
					<div class="container-fluid">
						<div class="nav-collapse">
							<div class="row-fluid">
								<div class="span2">
									<a href="<?php echo $this->request->webroot;?>dynamiques/DynamiqueOfTable/<?php echo $satable['Table']['id'];?>/<?php echo $versionencours['Version']['id'];?>" class="btn btn-info btn-small" >
										<i class="icon-pencil icon-white"></i><?php echo __(' Lignes')?>
									</a>
								</div>
								<div class="span2">
									<p>
										<a href="#?w=500" rel="popup_name" class="btn btn-inverse btn-small poplight" ><i class="icon-share icon-white"></i><?php echo __(' Generer')?></a>
									</p>
								</div>
								<div class="span8">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
	
			<div class="page-header">
				<?php if (!empty($satable['Colonne'])):?>
					<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered scrolly" id="myDataTable">
						<thead>
							<tr style="height: 0px;">
								<td width="10px" height="0px" style="white-space: nowrap" />
								<td height="0px" style="white-space: nowrap" ><input type="text" style="width: 50px"  name="search_engine" value="Search" class="search_init" /></td>
								<?php foreach ($satable['Colonne'] as $colonne): 
									if (is_numeric($colonne['longueur']) && $colonne['longueur']!=0 ){
										$longueur=$colonne['longueur'];
									}else{
										$longueur=8;
									}
									if ($colonne['pgtypecol_id']==2 ||$colonne['pgtypecol_id']==3){
										$longueur=8;
									}
									if($longueur>25){
										$longueur=25;
									}
										
									echo '<td><input class="search_init" value="Search" name=search_"'.h($colonne['name']).'" height="0px" style="width: '.($longueur*10).'px"/></td>';
								endforeach; ?>
							</tr>
							<tr style="height: 0px;">
								<th width="10px" style="white-space: nowrap" />
								<th width="10px" id="id" style="white-space: nowrap" >id</th>
								<?php foreach ($satable['Colonne'] as $colonne): ?>
									<th style="white-space: nowrap" class="editable" id="<?php echo h($colonne['name']);?>" name="<?php echo h($colonne['name']);?>" class="editable" data-content="<?php echo nl2br($colonne['description']);?>">
										<?php  if($colonne['topPk']==1) echo '<span class="label label-important"><i class="icon-asterisk icon-white"></i></span>';?>
										 <a id="<?php echo h($colonne['name']);?>_a" title="<?php echo h($colonne['name']);?>" data-content="<?php echo nl2br($colonne['description']);?>" >
										 	<?php echo h($colonne['name']);?>
										 <a>
									</th>
								<?php endforeach; ?>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td colspan="5" class="dataTables_empty">Loading data from server</td>
							</tr>
						</tbody>
					</table>
					<script type="text/javascript" charset="utf-8">
					  	$(function () {
					  		<?php foreach ($satable['Colonne'] as $colonne): 
								echo "$('#".h($colonne['name'])."_a').popover('hide');";
							endforeach; ?>
						    //$('#test').popover('hide');
							//$('#test3').tooltip('hide');
						})
					</script>
				<?php endif; ?>
			</div>
		</div>
	</div>
</div></div></div>

<!-- Chargement des onglets-->
<script type="text/javascript" charset="utf-8">
  	$(function () {
    	$('.tabs a:last').tab('show')
  	})
</script>

<!-- met a jour le lien href pour ouvrir la popup de generation de script-->
<script type="text/javascript">
	$(document).ready(function() {
		//Lorsque vous cliquez sur un lien de la classe poplight et que le href commence par #
		$('a.poplight[href^=#]').click(function() {
			window.showModalDialog("<?php echo $this->request->webroot;?>dynamiques/PopupGenererScript/<?php echo $satable['Table']['id'];?>/<?php echo $rupture_id;?>","nom_fenetre","params_fenetre" );

			return false;
		});
		//Lorsque vous cliquez sur un lien de la classe poplight et que le href commence par #
		
		//alert('rleb');
	});
</script>

<script type="text/javascript">
	$(document).ready( function () {

		var table_id='#myDataTable';

		var oTable;
	
		//************************************************************************************
		//GESTION des filtres sur chaque colonnes 
		//************************************************************************************
		// Use the elements to store their own index 
		$("thead input").each( function (i) {
			this.visibleIndex = i;
		} );
		
		$("thead input").keyup( function () {
			//If there is no visible index then we are in the cloned node
			var visIndex = typeof this.visibleIndex == 'undefined' ? 0 : this.visibleIndex;
			
			//Filter on the column (the index) of this element 
			oTable.fnFilter( this.value, visIndex );
		} );
		
		//
		// Support functions to provide a little bit of 'user friendlyness' to the textboxes
		//
		$("thead input").each( function (i) {
			this.initVal = this.value;
		} );
		
		$("thead input").focus( function () {
			if ( this.className == "search_init" )
			{
				this.className = "";
				this.value = "";
			}
		} );
		
		$("thead input").blur( function (i) {
			if ( this.value == "" )
			{
				this.className = "search_init";
				this.value = this.initVal;
			}
		} );
		//************************************************************************************
   

		oTable = 
        $(table_id).dataTable({
	        //"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
	        //Pour chaque colonne de la ligne
				//	si la classe du <th> contient 'editable' 
				//	alors on met la classe editable sur le <td>
	            // for ( var i=0 ; i<$('td', nRow).length ; i++ ){
	            // 	if ($(table_id + ' thead th').eq(i).attr('class').indexOf("editable")>=0 &&
	            // 		!($('td', nRow).eq(i).attr('class').indexOf("editable")>=0)){
	            // 		$('td', nRow).eq(i).attr('class','editable ' + $('td', nRow).eq(i).attr('class'));
	            // 	}
	            // }
	            /* Pour chaque colonne de la ligne on met l'attribut 'nowrap' */
	            //$('td', nRow).attr('nowrap','nowrap');
	            //$('td', nRow).attr('onclick','alert(\'rleb\')');
	            //return nRow;
	        //},
	         //fnInitComplete: function() {
	         	//alert($('table tbody tr').eq(0).attr('id'));
			//	$('table tbody tr').focusin( function() {
			 //       $(this).toggleClass('row_selected');
			  //  } );
	         //},
		 	//"sScrollXInner": "150%",
		 	//"bScrollCollapse": true,
			fnDrawCallback: function ( oSettings ) {

				/* Need to redo the counters if filtered or sorted */
				if ( oSettings.bSorted || oSettings.bFiltered ) {
					for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ) {
						var nTr = oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ;
						this.fnUpdate( i+1, nTr, 0, false, false );
					}
				}		

				$('#myDataTable td').attr('style','white-space: nowrap');

				//$('#myDataTable td').text('<input type="text" value="rleb"/>');

				/* Add/remove class to a row when clicked on */
				$('#myDataTable tbody tr').click( function() {
			        $(this).toggleClass('row_selected');
			    } );
			},
		 	"sScrollY": "250px",
		 	"sScrollX": "100%",
		 	//"sScrollXInner": "150%",
		 	"bScrollCollapse": true,
	        //"bJQueryUI": true,
            "bServerSide": true,
	        "bStateSave": false,
	        //"bLengthChange": true,
	        //"bInfo": true,
	        //"bAutoWidth": false,
	        "bDeferRender" : false,
        	"bPaginate": true,
	        //"bFilter" : false,
	        "bProcessing": true,
	        //"bSortClasses" : true,
			//"sDom": 'C<"clear">lfrtip',
		 	//"bScrollInfinite" : true,
		 	"aoColumnDefs": [
				{ "bSortable": false, "sClass": "index", "aTargets": [ 0 ] }
			],
			"aaSorting": [[ 1, 'asc' ]],

			// "aoColumnDefs": [
			// 	{ "bVisible": false, "aTargets": [ 1 ] }
			// ],
	        // "oLanguage": {
	        //     "sSearch": "Search all columns:"
	        // },
            "sPaginationType": "full_numbers",
            "sAjaxSource": "<?php echo $this->request->webroot;?>dynamiques/ChargerLignes_ajax/<?php echo $satable['Table']['id'];?>/<?php echo $rupture_id;?>",
			"aoColumns": [
				{ "mDataProp": "RNUM" }
				,{ "mDataProp": "ID" }
				<?php foreach($satable['Colonne'] as $colonne){
					echo ', { "mDataProp": "'.$colonne['name'].'" }';
				}?>
			]
            //,
			//"fnServerData": fnServerObjectToArray( [ 'id', 'codsoc', 'codtbl', 'cletbl', 'lib1' ] ),
			// "fnServerData": function( sUrl, aoData, fnCallback ) {
   //          	$.ajax( {
	  //               "url": sUrl,
	  //               "data": aaData,
	  //               "success": fnCallback,
	  //               "dataType": "jsonp",
	  //               "cache": false
	  //           } );

   //      	}
   //      	,
   //          "aoColumns":[
   //          	{
   //              	"bVisible" : false
   //             	},
   //              {},
   //              {},
   //              {},
   //              {}
   //          ]
        });
		

	    
		//new FixedColumns( oTable );
	 	/*var a = new FixedColumns( oTable, {
	 	 	"iLeftColumns": 1,
			"iLeftWidth": 75
	 	} );*/
	} );

	/* Get the rows which are currently selected */
	function fnGetSelected( oTableLocal )
	{
	    return oTableLocal.$('tr.row_selected');
	}
</script>




			
